@extends('admin.app')

@section('breadcrumb')
    <div class="bg-light lter b-b wrapper-md">
        <ol class="breadcrumb bg-light lter m-n no-padder">
            <li><a href="{{ admin_action('HomeController@index') }}">主页</a></li>
            <li>业务管理</li>
            <li class="active">用户管理</li>
        </ol>
    </div>
@endsection

@section('content')
    <div class="panel panel-default">
        <div class="panel-heading font-bold">
          投资人管理
        </div>
        <div class="row wrapper">
        	<!-- 1 start -->
        	<div class="col-sm-10">
                <form class="form-horizontal" method="get"
                      action="{{admin_action('Business\SalesStatisticsController@userList')}}">
                    <div class="row">
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">投资人:</label>
                                <div class="col-sm-8">
                                    <input class="form-control" type="text" placeholder="姓名 用户名 手机号" name="userKey"
                                           value="{{ $query['userKey'] }}"/>
                                </div>
                            </div>
                        </div>

                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">经纪人:</label>
                                <div class="col-sm-8">
                                    <input class="form-control" type="text" placeholder="姓名" name="broker_name"
                                           value="{{ $query['broker_name'] }}"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">机构:</label>
                                <div class="col-sm-8">
                        <select class="form-control org_yxjg" name="org_code" data-dept-url="{{ admin_action('Business\UsersController@orgDept') }}" data-rule-required="true">
                            <option value="">
                                请选择营销机构
                            </option>
                            @foreach($all_org as $org)
                                <option value="{{ $org->code }}" {{ $query['org_code'] == $org->code?'selected=selected':'' }}>{{ $org->company_name }}({{ $org->description }})</option>
                            @endforeach
                        </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-5">
                            <div class="form-group">
                                <label class="control-label col-sm-4">部门:</label>
                                <div class="col-sm-8">
                        <select class="form-control org_dept" data-rule-required='true' name='dept_code'>
                            <option value="">
                                请选择机构下属部门
                            </option>
                        </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-sm-1 text-left">
            <span class="input-group-btn">
              <button class="btn btn-sm btn-default" type="submit">查询</button>
            </span>
                        </div>
                    </div>
                </form>
            </div>
            <div class="col-sm-2 text-right text-center-xs">

                <a class="btn btn-xs btn-primary"
                       href="{{ admin_action('Business\SalesStatisticsController@index') }}"
                       data-toggle="tooltip" title="投资记录">
                    <i class="fa fa-tasks"></i>
                </a>
                <a class="btn btn-xs btn-primary"
                       href="{{ admin_action('Business\SalesStatisticsController@brokerList') }}"
                       data-toggle="tooltip" title="经纪人管理">
                    <i class="fa fa-group"></i>
                </a>
                  <a class="btn btn-xs btn-primary"
                       href="{{ admin_action('Business\SalesStatisticsController@userList') }}"
                       data-toggle="tooltip" title="客户管理">
                    <i class="fa fa-user"></i>
                </a>
              
            </div>
        	<!-- 1 end -->
        </div>
        <div class="table-responsive">

           <table class="table table-striped b-t b-light">
                <thead>
                <tr>
                    <th>id</th>
                    <th>姓名</th>
                    <th>用户名</th>
                    <th>电话号码</th>
                    <th>经纪人</th>
                    <th>部门</th>
                    <th>注册时间</th>
                </tr>
                </thead>
                <tbody>
                @forelse ($users as $user)
                    <tr>
                    	<td>{{ $user->id }}</td>
                    	<td>{{ $user->name??'--' }}</td>
                    	<td>{{ $user->username??'--' }}</td>
                    	<td>
				            @if(!empty($user->phone_number))
				              {{substr($user->phone_number, 0, 3) . '******' . substr($user->phone_number,7) }}</p>
				            @else
				              --
				            @endif
                    	</td>
                    	<td><a href="{{ admin_action('Business\SalesStatisticsController@brokerInfo',['id'=>$user->broker_id]) }}"
                       data-toggle="tooltip" title="经纪人详情" >{{ $user->broker_name??'--' }}</a></td>
                    	<td>{{ $user->dept??'--' }}</td>
                    	<td>{{ $user->created_at }}</td>
                    	<td>
                    		  <a class="btn btn-xs btn-primary" href="{{ admin_action('Business\SalesStatisticsController@userInfo',['id'=>$user->id]) }}"
                       data-toggle="tooltip" title="用户详情">
                    <i class="fa fa-info"></i>
                </a>
                <a class="btn btn-xs btn-primary" href="{{ admin_action('Business\SalesStatisticsController@transactionRecord',['id'=>$user->id]) }}"
                       data-toggle="tooltip" title="交易流水">
                    <i class="fa fa-align-left"></i>
                </a>
                <a class="btn btn-xs btn-primary"
                       href="{{ admin_action('Business\SalesStatisticsController@userToAgent',['user_id'=>$user->id]) }}"
                       data-toggle="tooltip" title="提升为经纪人">
                    <i class="fa fa-arrow-up"></i>
                </a>
                    	</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" class="text-center">没有找到客户投资记录</td>
                    </tr>
                @endforelse
                </tbody>
            </table>

        </div>
        <div class="panel-footer">
            <div class="row">
                <div class="col-sm-12 text-right text-center-xs">
                	{!! $links !!}
                </div>
            </div>
        </div>
    </div>
@endsection
@section('scripts')
    <script type="text/javascript">
        var dept_code = '{{ $query['dept_code'] }}';
        $(function(){
            //动态查询营销机构的部门
            $('.org_yxjg').change(function(){
                $dept_url = $(this).data('dept-url');
                $org_code = $(this).find('option:selected').val();
                $('.org_dept').html("");
                //异步查询营销机构下级部门
                $.ajax({
                    url:$dept_url,
                    data:{org_code:$org_code},
                    success:function(data){
                        node = '';
                        if(data.length > 0){
                            for(var i in data){
                                if(dept_code === data[i]["code"])
                                    node = node+'<option selected=selected value ='+data[i]["code"]+'>'+data[i]["name"]+'</option>';
                                else
                                    node = node+'<option value ='+data[i]["code"]+'>'+data[i]["name"]+'</option>';
                            }
                            $('.org_dept').append($(node));
                        }else{
                            node = node+'<option value ='+""+'>'+"  --  "+'</option>';
                            $('.org_dept').append($(node));
                        }
                    }
                });
            });
            $('.org_yxjg').trigger("change");
        });
    </script>
@endsection